#!/usr/bin/env python 
# -*- coding:utf-8 -*-
'''
任务数据库操作模型
'''
from app.models.Model import ToTask
from app.models.BaseModel import *
from sqlalchemy_serializer import SerializerMixin


class TaskModel(ToTask, BaseModel, SerializerMixin):
    @staticmethod
    def getTask(filters: set, order: str = 'id desc', field: tuple = ()):
        rows = TaskModel().getOne(TaskModel, filters=filters, order=order, field=field)
        return rows

    @staticmethod
    def getAllTask(filters: set = None, order: str = 'id asc', field: tuple = (), limit: int = 0):
        '''
        获取所有任务列表
        :param filters:
        :param order:
        :param field:
        :param limit:
        :return:
        '''
        rows = TaskModel().getAll(TaskModel, filters, order, field, limit)
        return rows

    @staticmethod
    def getPageList(filters: set, order: str = 'id asc', field: tuple = (), page: int = 1, limit: int = 20):
        result = BaseModel().getList(TaskModel, filters, order, field, page, limit)
        try:
            response = {
                'count':result['page']['count'],
                'current':result['page']['current_page'],
                'total':result['page']['total_page'],
                'data':result['list']
            }
        except KeyError as err:
            return str(err)
        return response

    @staticmethod
    def createdTask():
        ...
